package com.qjdchina.sku.biz.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.SmsRecordManager;
import com.qjdchina.sku.dao.mapper.SmsRecordMapper;
import com.qjdchina.sku.model.SmsRecord;
import com.qjdchina.sku.service.enums.SkuResultCode;

@Service
public class SmsRecordManagerImpl implements SmsRecordManager {

	@Autowired
	private SmsRecordMapper smsRecordMapper;

	@Override
	@Transactional
	public Result<String> addRecord(SmsRecord smsRecord) {
		int i = smsRecordMapper.insert(smsRecord);
		if (i==0) {
			return new Result<String>(SkuResultCode.ADD_FAIL);
		}
		return new Result<String>(SkuResultCode.SUCCESS,true);
	}

	@Override
	@Transactional
	public Result<String> updateRecord(SmsRecord smsRecord) {
		int i = smsRecordMapper.updateByPrimaryKeySelective(smsRecord);
		if (i==0) {
			return new Result<String>(SkuResultCode.UPDATE_FAIL);
		}
		return new Result<String>(SkuResultCode.SUCCESS);
	}

	@Override
	public Result<SmsRecord> getSmsRecordByMobile(String mobile) {
		SmsRecord record = smsRecordMapper.getSmsRecordByMobile(mobile);
		if (record == null) {
			return new Result<SmsRecord>(SkuResultCode.DATA_NOT_EXIST);
		}
		return new Result<SmsRecord>(record);
	}
}
